package xyz.dava.sync.fm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import xyz.dava.sync.fm.service.SyncService;

import java.lang.reflect.InvocationTargetException;

@Controller
public class SyncController {

    @Autowired
    private SyncService service;

    @RequestMapping("/index")
    public String index(Model model) {
        return "index";
    }

    @ResponseBody
    @RequestMapping("/sync/{type}")
    public String sync(@PathVariable String type) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        SyncService.class.getDeclaredMethod("sync"+type).invoke(service);
        return "success";
    }
}
